var __UICardQualityUp_instance = null;
function getUICardQualityUp() { return __UICardQualityUp_instance; }

var UICardQualityUp = function(){};

UICardQualityUp.prototype.onDidLoadFromCCB = function()
{
    cc.log("UICardQualityUp.onDidLoadFromCCB");
    __UICardQualityUp_instance = this;

    // 当前卡牌
    this._curCard = -1;

    // 左边,右边
    var card = new CardImage('', '', 0, 0);
    card.setPosition(cc.p(24,73));
    card.setScale(0.9); // 缩放大小
    card.showImage(false);
    this.uiWindow.addChild(card);
    this._leftCard = card;

    cc.log('test')
    card.setData('res/item/1.png', 'test', 0, 1);

    card = new CardImage('', '', 0, 0);
    card.setPosition(cc.p(341,73));
    card.setScale(0.9); // 缩放大小
    card.showImage(false);
    this.uiWindow.addChild(card);
    this._rightCard = card;

};

// 发送设置主界面数据
UICardQualityUp.prototype.updateData = function()
{
    cc.log('UICardQualityUp.updateData');

    if(this._curCard) {
        this.setCurrent(this._curCard);
    }
}

UICardQualityUp.prototype.setCurrent = function(cardId)
{
    cc.log('UICardQualityUp.setCurrent');

    this._curCard = cardId;

    setCardImage(this._leftCard, cardId);
    this._leftCard.showImage(true);

    // Quality+1显示到右边
    card = DataManager.playerCardData[cardId];
    setCardImage(this._rightCard, cardId);
    this._rightCard.setQuality(card.quality + 1);
    this._rightCard.showImage(true);
}


UICardQualityUp.prototype.onLevelUp = function() 
{
    if(this._curCard == -1) return;
    
    function _func (data) {
        if(data['result']=='ok') {
            // 刷新数据
            DataManager.setData(data['data']);
            // 刷新界面
            getUICardQualityUp().updateData();
        }
    };
    gnet.sendHttp("card_quality_up", [this._curCard], _func);
}

UICardQualityUp.prototype.onCancel = function() 
{
    cc.log('UICardQualityUp.onCancel');
    getUIMain().showUICardQualityUp(false);
}




